import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router'
import index from '@/pages/index.tsx'
import user from '@/store/modules/user'
// import store from '@/store/index'
// import { getUserInfo } from '@/api/user'

const routes: Array<RouteRecordRaw> = [
  {
    path: '/',
    component:  ()=> import(/* webpackChunkName: "department" */ '../pages/index.vue'),
  },
  {
    path: '/note',
    component:  ()=> import(/* webpackChunkName: "department" */ '../pages/note/index.vue'),
  },
  {
    path: '/note/:id',
    component:  ()=> import(/* webpackChunkName: "department" */ '../pages/note/id.vue'),
  },
  {
    path: '/admin',
    component:  ()=> import(/* webpackChunkName: "department" */ '../pages/admin/index'),
    children:[
      {
        path:'user',
        component:  ()=> import(/* webpackChunkName: "department" */ '../pages/admin/user'),
      }
    ]
  },
  
  // {
  //   path: '/demo',
  //   name: 'demo',
  //   component:  import(/* webpackChunkName: "department" */ '../views/demo/index.vue'),
  //   // children: [
  //   //   {
  //   //     name: 'department',
  //   //     path: 'department',
  //   //     redirect: '/views/department/list',
  //   //     component: () => import('@/components/page'),
  //   //     children: [
  //   //       {
  //   //         name: 'department-list',
  //   //         path: 'list',
  //   //         component: () =>
  //   //           import(/* webpackChunkName: "department" */ '../views/department/index.vue')
  //   //       },
  //   //       {
  //   //         name: 'department-detail',
  //   //         path: 'detail',
  //   //         component: () =>
  //   //           import(/* webpackChunkName: "department" */ '../views/department/detail.vue')
  //   //       }
  //   //     ]
  //   //   },
  //   // ]
  // }
]

const router = createRouter({
  // 4. 内部提供了 history 模式的实现。为了简单起见，我们在这里使用 hash 模式。
  history: createWebHistory(),
  routes // `routes: routes` 的缩写
})

// const ignorePage = [
//   '/',
//   '/login'
// ]
// // const store = useStore('key')
// function initStore (data = {}) { // 设置或者初始化 vuex中的登录信息
//   // store.commit('changeInfo', data)
// }
// router.beforeEach(async (to, from, next) => {
//   // if (to.path === from.path) return next()

//   // if (!ignorePage.includes(to.path)) { // 在这里添加 ignore 验证登录的页面
//   //   const { data } = await getUserInfo()
//   //   initStore(data)
//   //   next()
//   // } else {
//     // initStore()
//     next()
//   // }
// })

export default router
